package leet.ku._66;

public class Solution {
    public int[] plusOne(int[] digits) {
        if (digits == null || digits.length <= 0)
        	return digits;
        
        int i = digits.length - 1;
        while (i >= 0 && digits[i] == 9)
        	digits[i--] = 0;
        if (i >= 0) {
        	digits[i]++;
        	return digits;
        } else {
        	digits = new int[digits.length + 1];
        	digits[0] = 1;
        	return digits;
        }
    }
}